package com.yhd.controller;

import com.yhd.entity.dto.CycleImgDto;
import com.yhd.entity.dto.SystemDictionaryDto;
import com.yhd.entity.query.CycleImgVO;
import com.yhd.entity.query.SystemDictionaryVO;
import com.yhd.entity.result.ResultVo;
import com.yhd.model.ResultPage;
import com.yhd.service.CycleImgService;
import com.yhd.service.SysDictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@Api(value = "banner管理")
@Slf4j
@RequestMapping(value = "/banner")
@CrossOrigin
public class CycleImgController extends WebBaseController {

    @Autowired
    private CycleImgService cycleImgService;



    @ApiOperation(value = "获取banner列表", notes = "获取banner列表")
    @ApiImplicitParams({})
    @GetMapping("/list")
    @ResponseBody
    public ResultVo<List<CycleImgDto>> selectCycleImgList(CycleImgVO cycleImgVO){
        List<CycleImgDto> cycleImgDtoList = cycleImgService.selectCycleImgList(cycleImgVO);
        return ResultVo.success(cycleImgDtoList);
    }

    @ApiOperation(value = "获取banner详情", notes = "获取banner详情")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "bannerid", required = true, paramType = "字符串")})
    @GetMapping("/info")
    @ResponseBody
    public ResultVo<CycleImgDto> selectCycleImgInfo(CycleImgVO cycleImgVO){
        CycleImgDto cycleImgDto = cycleImgService.selectCycleImgInfo(cycleImgVO);
        return ResultVo.success(cycleImgDto);
    }

    @ApiOperation(value = "新增/修改banner", httpMethod = "POST", notes = "{\n" +
            "  \"id\": \"banner id 修改不能为空\",\n" +
            "  \"title\": \"标题\",\n" +
            "  \"img\": \"图片\",\n" +
            "  \"bizType\": \"类型 activity:活动，course:课程\",\n" +
            "  \"bizId\": \"业务id，活动或者课程id\",\n" +
            "  \"sort\": \"排序\"\n" +
            "}")
    @PostMapping("/putBanner")
    @ResponseBody
    public ResultVo<CycleImgDto> putBanner(@RequestBody CycleImgVO cycleImgVO) {
        CycleImgDto cycleImgDto = cycleImgService.putBanner(cycleImgVO,getUserInfo(request));
        if (null != cycleImgDto){
            return ResultVo.success(cycleImgDto);
        }
        return ResultVo.failure("10003","操作失败。");
    }

    @ApiOperation(value = "删除banner", httpMethod = "DELETE", notes = "{\n" +
            "  \"id\": \"bannerid\"\n" +
            "}")
    @DeleteMapping("/delete")
    @ResponseBody
    public ResultVo<Boolean> deleteCycleImg(@RequestBody CycleImgVO cycleImgVO) {
        boolean deleteCycleImg = cycleImgService.deleteCycleImg(cycleImgVO);
        if (deleteCycleImg){
            return ResultVo.success(deleteCycleImg);
        }
        return ResultVo.failure("10003","操作失败。");
    }

}
